import { request } from "@/utils/http";
import { Key } from "react";
import { 
    reqGetHospitalSetListParmas, 
    ReqHospitalSetListResponse,
    ReqAddHospitalParams,
    HospitalSetItem,
    ReqUpdateHospitalParams
} from './model/hospitalSetTypes'

// 获取医院设置的列表数据
// 如果不定义数据类型，ts还是报错状态
export const reqGetHospitalSetList = (
    { page, limit, hosname, hoscode }: reqGetHospitalSetListParmas
    ) => {
    return request.get<any, ReqHospitalSetListResponse>(
        `/hos/admin/hosp/hospitalSet/${page}/${limit}`, 
        { params: { hosname, hoscode } }
    );
};

// 添加医院请求函数
export const reqAddHospital = (hospital: ReqAddHospitalParams) => {
    // post 一般没有请求行的路径参数
    // post 的请求体就是一个对象
    // 添加/更新/删除 请求返回的响应数据的属性为null
    return request.post<any, null>('/hos/admin/hosp/hospitalSet/save', hospital)
}


// 编辑医院 - 回写数据
export const reqGetHospital = (id: number) => {
    // get 请求，需要携带id
    return request.get<any, HospitalSetItem>(`/hos/admin/hosp/hospitalSet/get/${id}`)
}

// 修改医院的请求
export const reqUpdateHospital = (hospital: ReqUpdateHospitalParams) => {
    // 修改医院，使用put请求
    return request.put<any, null>(`/hos/admin/hosp/hospitalSet/update`, hospital)
}

// 删除医院接口
export const reqRemoveHospital = (id: number) => {
    // 修改医院，使用put请求
    return request.delete<any, null>(`/hos/admin/hosp/hospitalSet/remove/${id}`)
}


// 根据ids批量删除医院
export const reqRemoveHospitalList = (ids: Key[]) => {
    return request.delete<any, null>(`/hos/admin/hosp/hospitalSet/batchRemove`, {
        // 文档要求携带的数据既不是path，也不是query，而是 body
        data: ids
    })
}